package db

import (
	"fmt"

	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

var DB *gorm.DB
var err error // init()方法在模块被引入时自动执行
func Init() {
	fmt.Println("db, Init")

	dsn := "root:Chenhao$123456@tcp(linux.server:3306)/gin_demo?charset=utf8mb4&parseTime=True&loc=Local"
	DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println("db connected")
}
